//GA MPI onemax
//$Id: onemax_ga_mpi.cpp 395 2010-03-26 14:01:03Z Oleg.Bulychov $

#include "stdafx.h"

#include "../../onemax.h"
#include "solvers/ga/ga_mpi.h"
#include "src/heo/include/run_mpi.h"

typedef OneMax_Problem  TProblem;
typedef OneMax_Solution TSolution;
typedef OneMax_Config   TConfig;

typedef Environment<TProblem, TSolution, TConfig>   TEnvironment;

typedef struct GA_Traits<TEnvironment>              TTraits;
typedef GA_MPI<TTraits>                             TSolver;

static struct ga_register
{
    ga_register()
    {
        TSolver::register_Selection< ga::selection::tournament_selection >();
        TSolver::register_Selection< ga::selection::roulette_selection >();
        TSolver::register_Selection< ga::selection::random_selection >();

        TSolver::register_Operator< ga::inter_operator::crossover>();
        TSolver::register_Operator< ga::inter_operator::mutation>();
    }
} reg;

namespace mpi
{

class communicator2:
    public communicator
{
public:
    explicit communicator2()
    {}

};

}
/*
void test1(int argc, char* argv[])
{
    using namespace std;
    mpi::implementation impl(argc, argv);
    mpi::communicator2 comm;
    int rank  = comm.rank();
    int np = comm.size();

    unsigned int rand_seed = ::strtol(argv[1], NULL, 0);
    uniform_random::randomize(1, rand_seed, rank);
    uniform_random rnd(0);
    int my_number = rnd.next_UInt(10);
    cout << "rank " << rank << " from " << np << ", rnd=" << my_number << lf;

    if (!rank)
    {
        int sum = 0;
        comm.reduce(my_number, sum, MPI_SUM, 0);
        cout << "sum=" << sum << lf;
    }
    else
    {
        comm.reduce(my_number, MPI_SUM, 0);
    }

    int m = 0;
    comm.all_reduce(my_number, m, MPI_MAX);
    cout << "max=" << m << lf;
}
*/
int main(int argc, char* argv[])
{
    //test1(argc, argv);
    //return 0;
    return Run_MPI<TSolver>(argc, argv);
}

